package cc.mcggdd.leah.boot.stock.controller;

import cc.mcggdd.leah.boot.stock.service.StockBondReverseRepoService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cc.mcggdd.leah.boot.stock.model.form.StockBondReverseRepoForm;
import cc.mcggdd.leah.boot.stock.model.query.StockBondReverseRepoQuery;
import cc.mcggdd.leah.boot.stock.model.vo.StockBondReverseRepoVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import cc.mcggdd.leah.boot.common.result.PageResult;
import cc.mcggdd.leah.boot.common.result.Result;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;

/**
 * 国债逆回购前端控制层
 *
 * @author 
 * @since 2025-02-08 12:39
 */
@Tag(name = "国债逆回购接口")
@RestController
@RequestMapping("/api/v1/stockBondReverseRepos")
@RequiredArgsConstructor
public class StockBondReverseRepoController  {

    private final StockBondReverseRepoService stockBondReverseRepoService;

    @Operation(summary = "国债逆回购分页列表")
    @GetMapping("/page")
    @PreAuthorize("@ss.hasPerm('stock:stockBondReverseRepo:query')")
    public PageResult<StockBondReverseRepoVO> getStockBondReverseRepoPage(StockBondReverseRepoQuery queryParams ) {
        IPage<StockBondReverseRepoVO> result = stockBondReverseRepoService.getStockBondReverseRepoPage(queryParams);
        return PageResult.success(result);
    }

    @Operation(summary = "新增国债逆回购")
    @PostMapping
    @PreAuthorize("@ss.hasPerm('stock:stockBondReverseRepo:add')")
    public Result<Void> saveStockBondReverseRepo(@RequestBody @Valid StockBondReverseRepoForm formData ) {
        boolean result = stockBondReverseRepoService.saveStockBondReverseRepo(formData);
        return Result.judge(result);
    }

    @Operation(summary = "获取国债逆回购表单数据")
    @GetMapping("/{id}/form")
    @PreAuthorize("@ss.hasPerm('stock:stockBondReverseRepo:edit')")
    public Result<StockBondReverseRepoForm> getStockBondReverseRepoForm(
        @Parameter(description = "国债逆回购ID") @PathVariable Long id
    ) {
        StockBondReverseRepoForm formData = stockBondReverseRepoService.getStockBondReverseRepoFormData(id);
        return Result.success(formData);
    }

    @Operation(summary = "修改国债逆回购")
    @PutMapping(value = "/{id}")
    @PreAuthorize("@ss.hasPerm('stock:stockBondReverseRepo:edit')")
    public Result<Void> updateStockBondReverseRepo(
            @Parameter(description = "国债逆回购ID") @PathVariable Long id,
            @RequestBody @Validated StockBondReverseRepoForm formData
    ) {
        boolean result = stockBondReverseRepoService.updateStockBondReverseRepo(id, formData);
        return Result.judge(result);
    }

    @Operation(summary = "删除国债逆回购")
    @DeleteMapping("/{ids}")
    @PreAuthorize("@ss.hasPerm('stock:stockBondReverseRepo:delete')")
    public Result<Void> deleteStockBondReverseRepos(
        @Parameter(description = "国债逆回购ID，多个以英文逗号(,)分割") @PathVariable String ids
    ) {
        boolean result = stockBondReverseRepoService.deleteStockBondReverseRepos(ids);
        return Result.judge(result);
    }
}
